using System;
using MbUnit.Framework;
using DotNetNukeMVPWizard.ProjectConfiguration;

namespace DotNetNukeMVPWizard.Tests
{
    [TestFixture]
    public class TestTextConfiguration
    {
        #region Properties
        private const string STR_KeyName = "KeyName";
        private const string STR_Value = "Value";
        private IConfigurable Actual;
        #endregion

        #region SetUp
        [SetUp]
        public void SetUp()
        {
            Actual = new TextConfiguration(STR_KeyName);
        }
        #endregion

        #region Test Constructor
        [Test]
        [Description("Ensure that the constructor sets the Key name")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void TextConfiguration_Sets_Key()
        {
            Assert.AreEqual(STR_KeyName, Actual.Key);
        }

        [Test]
        [Description("Ensure that the constructor sets the Value to an empty string")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void TextConfiguration_Sets_Value()
        {
            Assert.IsNotNull(Actual.Value);
            Assert.AreEqual(string.Empty, Actual.Value);
        }

        [Test]
        [Description("Ensure that the constructor sets IsOptional to the default value of false")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void TextConfiguration_Sets_IsOptional_To_False()
        {
            Assert.IsFalse(Actual.IsOptional);
        }

        [Test]
        [Description("Ensure that the constructor sets IsOptional to true")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void TextConfiguration_Sets_IsOptional_To_True()
        {
            Actual = new TextConfiguration(STR_KeyName, string.Empty, true);
            Assert.IsTrue(Actual.IsOptional);
        }

        [Test]
        [Description("Ensure that the constructor checks for a valid key name (not null or empty)")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void TextConfiguration_Requires_Key()
        {
            Assert.Throws<ArgumentNullException>(() => { Actual = new TextConfiguration(null); });
            Assert.Throws<ArgumentNullException>(() => { Actual = new TextConfiguration(string.Empty); });
        }
        #endregion

        #region Test Properties
        // TODO: Add test for TextConfiguration.ErrorMessage

        [Test]
        [Description("Ensure that setting value to null generates an empty string")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void TextConfiguration_Set_Value_To_Null_Is_Transformed_To_Empty_String()
        {
            Actual.Value = null;
            Assert.AreEqual(string.Empty, Actual.Value);
        }

        [Test]
        [Description("Ensure that IsValid is false for a non-optional empty string")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void TextConfiguration_Gets_IsValid_False()
        {
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Description("Ensure that IsValid is true for an optional empty string")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void TextConfiguration_Gets_IsValid_True_For_Optional_And_Empty_String()
        {
            Actual = new TextConfiguration(STR_KeyName, string.Empty, true);
            Assert.IsTrue(Actual.IsValid);
        }

        [Test]
        [Description("Ensure that IsValid is true for a non-empty string")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void TextConfiguration_Gets_IsValid_True_For_Non_Empty_String()
        {
            Actual.Value = STR_Value;
            Assert.IsTrue(Actual.IsValid);
        }
        #endregion
    }
}